<html>
 <head>
 <title>html+css+js实现复选框全选与反选</title>
 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
 <meta name="keywords" content="js,笔试题目" />
 <style type="text/css">
  table{
        border:1px solid gray;
        margin: 100px auto;
        width: 200px;
    }
 </style>
 </head>
 <body>
 <form id="form1">
  <table>
  <tr>
   <td><input type="checkbox" id="cb_quanxuan" onclick="quanxuan()" />全选</td>
  </tr>
  
  <tr>
   <td><input type="checkbox" id="cb1" value="1" />1</td>
  </tr>
  
  <tr>
   <td><input type="checkbox" id="cb2" value="2" />2</td>
  </tr>
  
  <tr>
   <td><input type="checkbox" id="cb3" value="3" />3</td>
  </tr>
  
  <tr>
   <td><input type="checkbox" id="cb_fanxuan" onclick="fanxuan()" />反选</td>
  </tr>
  </table>
 </form>
 </body>
</html>
 <script type="text/javascript">
  function quanxuan()
  {
  for(var i=1;i<=3;i++)
  {
   var cbox_id="cb"+i;
   var cbox=document.getElementById(cbox_id);
   //alert(cbox.value);
   if(document.getElementById("cb_quanxuan").checked)
   cbox.checked=true;
   else
   cbox.checked=false;;
  }
  }
  
  var fanhuan=document.getElementById("cb_fanxuan");
  function fanxuan(){
    for(var i=1;i<=3;i++){  
   var cbox_id="cb"+i;
   var cbox=document.getElementById(cbox_id);
   if(fanhuan.checked){
            if(cbox.checked){
                cbox.checked=false;
                }
            else{
                cbox.checked=true;
                }
   }
   else{ 
            if(cbox.checked){
                cbox.checked=false;
                }
            else{
                cbox.checked=true;
                }
        }
    }
  }
 </script>